﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DAO;

namespace Sklad.WindowsApplication
{
    public partial class AddProductToForm : Form
    {
        FormType ft;

        public AddProductToForm(FormType temp)
        {
            InitializeComponent();
            ft = temp;
            this.cb_product.Items.AddRange(AdminMainForm.dr.ProductRepository.GetAll().ToArray());
        }

        private void bt_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void bt_add_Click(object sender, EventArgs e)
        {
            var cur = this.cb_product.SelectedItem as Product;

            switch (ft)
            {
                case FormType.AddSendingForm:
                    AddSendingForm.itemlist.Add(
                            new TempClass()
                            {
                                Id = cur.Id,
                                Name = cur.Name,
                                Count = int.Parse(this.tb_col.Text),
                            });
                    break;
                case FormType.AddReceiveForm:
                    AddReceiveForm.itemlist.Add(
                            new TempClass()
                            {
                                Id = cur.Id,
                                Name = cur.Name,
                                Count = int.Parse(this.tb_col.Text),
                            });
                    break;
                default:
                    break;
            }

            this.Close();
        }
    }

    public enum FormType
    {
        AddSendingForm,
        AddReceiveForm
    }
}
